package ai.leinao.alarm.task;

import ai.leinao.common.domain.GatherData;
import ai.leinao.common.queue.MessageQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 定时触发告警
 *
 * @author zhong.wang
 * @date 2025/9/9
 **/
@Component
@Slf4j
public class ScheduleTriggerAlarm {

    @Resource
    private MessageQueue dataQueue;

    @Scheduled(cron = "0/5 * * * * ?")
    public void triggerAlarm() {
        // 模拟数据
        for (int i = 0; i < 2000; i++) {
            GatherData gatherData = new GatherData();
            gatherData.setDeviceModelId(123L);
            gatherData.setDeviceId(100L);
            gatherData.setDeviceTypeCode("nbq");
            gatherData.setTs(new Date());
            gatherData.setStationId(100L);
            gatherData.setAreaId(100L);
            gatherData.setDeptId(100L);
            Map<String,Object> fieldValueMap = new HashMap<>();
            fieldValueMap.put("temperature", 10 + Math.random() * 50);
            gatherData.setProperties(fieldValueMap);
            dataQueue.pushGatherData(gatherData);
        }
    }

}
